// 主进程到渲染进程(单向)
window.mainAPI.mainToRenderer((mainData) => {
    console.log('mainToRenderer => ', mainData)
})

// 渲染进程到主进程(单向)--1
window.mainAPI.rendererToMainOne('21')
// 渲染进程到主进程(单向)--2
window.mainAPI.rendererToMainTwo('21')

// 渲染进程与主进程(双向)--1
window.mainAPI.rendererAndMainEachOtherOne('1212-2121').then(res => {
    console.log("rendererAndMainEachOtherOne => ", res);
})
// 渲染进程与主进程(双向)--2
window.mainAPI.rendererAndMainEachOtherTwoSend('1212-2121')
window.mainAPI.rendererAndMainEachOtherTwoReceive((res) => {
    console.log("rendererAndMainEachOtherTwo => ", res);
})

// 传递其他主进程数据
console.log('当前处于electron环境 => ', process.type)
console.log('node.js版本 => ', window.mainAPI.nodeVersion())
console.log('chrome版本 => ', window.mainAPI.chromeVersion())
console.log('electron版本 => ', window.mainAPI.electronVersion())

const renderThumbnails = async () => {
    const hwndContainerDom = document.querySelector('.hwnd-container')
    hwndContainerDom.innerHTML = ''
    
    try {
        const sources = await window.mainAPI.desktopCapturer.getAllWindowsHwnd();
        
        sources.forEach(source => {
            const img = document.createElement('img');
            img.src = source.thumbnail;
            img.alt = source.name;
            img.style.cssText = `
                width: 200px;
                height: auto;
                margin: 10px;
                border: 2px solid transparent;
                cursor: pointer;
            `;
            hwndContainerDom.appendChild(img);
        });
    } catch (error) {
        console.error('缩略图渲染失败:', error);
    }
}

renderThumbnails();

